﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MappitLib;

namespace Mappit {
    public partial class FormMain : Form {
        //*********************************************************************
        #region Constants
        public const string OpenImageFileFilter =
            "Images|*.bmp;*.png;*.gif;*.jpg;*.jpeg|All files|*.*";
        #endregion
        //*********************************************************************
        #region Members
        private static CommandStack commands_ = new CommandStack();
        #endregion
        //*********************************************************************
        #region Properties
        public static CommandStack Commands {
            get { return commands_; }
        }
        #endregion
        //*********************************************************************
        #region Methods
        public FormMain() {
            InitializeComponent();
            layerBrowser.TilemapEditor = tilemapEditor;
        }
        private void OpenTilesetDialog() {
            DialogResult result = openTilesetDialog.ShowDialog();
            if (result != DialogResult.OK) {
                return;
            }
            Tileset tileset = new Tileset(openTilesetDialog.FileName);
            tilesetEditor.Tileset = tileset;
            tilemapEditor.Tileset = tileset;
            Refresh();
        }
        #endregion // Methods
        //*********************************************************************
        #region Event handlers
        private void undoToolStripMenuItem_Click(object sender, EventArgs e) {
            Commands.Undo();
        }

        private void redoToolStripMenuItem_Click(object sender, EventArgs e) {
            Commands.Redo();
        }

        private void openToolStripMenuItem_Click(object sender, EventArgs e) {
            OpenTilesetDialog();
        }

        private void tilemapEditor_RaiseTileDropEvent(object sender, TileDropEventArg e) {
            Command cmd = new CmdTilemap.SetTile(tilemapEditor, new Tile(tilesetEditor.SelectedTile),
                e.DropLocation);
            commands_.Execute(cmd);
        }
    }
        #endregion
}
